<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Java开发," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="说明：Java开发面试题。">
<meta name="keywords" content="Java开发">
<meta property="og:type" content="article">
<meta property="og:title" content="Java开发面试题">
<meta property="og:url" content="http://bebetter.site/2017/09/01/Algorithm/Java开发面试题/index.html">
<meta property="og:site_name" content="gatewayzy">
<meta property="og:description" content="说明：Java开发面试题。">
<meta property="og:updated_time" content="2017-09-01T05:58:10.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Java开发面试题">
<meta name="twitter:description" content="说明：Java开发面试题。">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"right","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://bebetter.site/2017/09/01/Algorithm/Java开发面试题/"/>

  <title> Java开发面试题 | gatewayzy </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">gatewayzy</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">blog of gatewayzy</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Java开发面试题
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2017-09-01T13:58:10+08:00" content="2017-09-01">
              2017-09-01
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/Algorithm/" itemprop="url" rel="index">
                    <span itemprop="name">Algorithm</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>说明：</strong>Java开发面试题。<br><a id="more"></a></p>
<p>参考文章：</p>
<h2 id="常规面试题"><a href="#常规面试题" class="headerlink" title="常规面试题"></a>常规面试题</h2><ol>
<li>HashMap的实现原理。</li>
<li>什么是AOP？AOP的使用场景？AOP的实现原理？</li>
<li>垃圾回收算法有哪些？</li>
<li>class装载步骤？</li>
<li>http的请求方法？</li>
<li>常用的http响应头？</li>
<li>简述java的内存模型</li>
<li>springboot的优势和劣势？</li>
<li>springcloud的优势和劣势以及springcloud的组成？</li>
<li>collection和collections的区别？</li>
</ol>
<h2 id="经典面试题"><a href="#经典面试题" class="headerlink" title="经典面试题"></a>经典面试题</h2><ol>
<li>jvm，jre以及jdk三者之间的关系？</li>
<li>synchronized是怎么实现锁的？</li>
<li>spring是怎么实现单例的？</li>
<li>mybaits中#和$两者的区别？</li>
<li>mysql的性能优化，你会考虑哪些？</li>
<li>tomcat的优化，你知道哪些？ <ol>
<li>关掉对web.xml的监视，把jsp提前编辑成Servlet。有富余物理内存的情况，加大tomcat使用的jvm的内存</li>
<li>服务器资源，服务器所能提供CPU、内存、硬盘的性能对处理能力有决定性影响。<br>　　        1. 对于高并发情况下会有大量的运算，那么CPU的速度会直接影响到处理速度。<br>　　        2. 内存在大量数据处理的情况下，将会有较大的内存容量需求，可以用-Xmx -Xms -XX:MaxPermSize等参数对内存不同功能块进行划分。我们之前就遇到过内存分配不足，导致虚拟机一直处于full GC，从而导致处理能力严重下降。<br>　　        3. 硬盘主要问题就是读写性能，当大量文件进行读写时，磁盘极容易成为性能瓶颈。最好的办法还是利用下面提到的缓存。</li>
<li>利用缓存和压缩<ol>
<li>对于静态页面最好是能够缓存起来，这样就不必每次从磁盘上读。这里我们采用了Nginx作为缓存服务器，将图片、css、js文件都进行了缓存，有效的减少了后端tomcat的访问。</li>
<li>为了能加快网络传输速度，开启gzip压缩也是必不可少的。但考虑到tomcat已经需要处理很多东西了，所以把这个压缩的工作就交给前端的Nginx来完成。</li>
<li>除了文本可以用gzip压缩，其实很多图片也可以用图像处理工具预先进行压缩，找到一个平衡点可以让画质损失很小而文件可以减小很多。曾经我就见过一个图片从300多kb压缩到几十kb，自己几乎看不出来区别。</li>
</ol>
</li>
<li>采用集群。单个服务器性能总是有限的，最好的办法自然是实现横向扩展，那么组建tomcat集群是有效提升性能的手段。我们还是采用了Nginx来作为请求分流的服务器，后端多个tomcat共享session来协同工作。可以利用nginx+tomcat+memcached组建web服务器负载均衡。</li>
<li>优化tomcat参数。这里以tomcat7的参数配置为例，需要修改conf/server.xml文件，主要是优化连接配置，关闭客户端dns查询。<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">&lt;Connector port=&quot;8080&quot;   </div><div class="line">protocol=&quot;org.apache.coyote.http11.Http11NioProtocol&quot;  </div><div class="line">connectionTimeout=&quot;20000&quot;  </div><div class="line">redirectPort=&quot;8443&quot;   </div><div class="line">maxThreads=&quot;500&quot;   </div><div class="line">minSpareThreads=&quot;20&quot;  </div><div class="line">acceptCount=&quot;100&quot; </div><div class="line">disableUploadTimeout=&quot;true&quot; </div><div class="line">enableLookups=&quot;false&quot;   </div><div class="line">URIEncoding=&quot;UTF-8&quot; /&gt;</div></pre></td></tr></table></figure>
</li>
</ol>
</li>
</ol>
<ol>
<li>缓存的雪崩以及穿透的理解？<ol>
<li>什么是缓存穿透：一般的缓存系统，都是按照key去缓存查询，如果不存在对应的value，就应该去后端系统查找。如果key对应的value是一直不存在，并且对该key并发请求量很大，就会对后端系统造成很大的压力。这就叫做缓存穿透。</li>
<li>避免缓存穿透：<ol>
<li>对查询结果为空的情况也进行缓存，缓存时间设置短一点，或者该key对应的数据insert了之后清理缓存。</li>
<li>对一定不存在的key进行过滤。可以把所有的可能存在的key放到一个大的Bitmap中，查询时通过该bitmap过滤。（第2种应该用的不多吧）</li>
</ol>
</li>
<li>什么是缓存雪崩？ 当缓存服务器重启或者大量缓存集中在某一个时间段失效，在失效的时候，也会给后端系统(如DB)带来很大压力。</li>
<li>如何避免缓存雪崩？ <ol>
<li>在缓存失效后，通过加锁或者队列来控制读数据库写缓存的线程数量。比如对某个key只允许一个线程查询数据和写缓存，其他线程等待。</li>
<li>不同的key，设置不同的过期时间，让缓存失效的时间点尽量均匀。</li>
<li>做二级缓存，A1为原始缓存，A2为拷贝缓存，A1失效时，可以访问A2，A1缓存失效时间设置为短期，A2设置为长期</li>
</ol>
</li>
</ol>
</li>
<li>HashMap的key可以重复吗？</li>
<li>synchronized和lock的区别？</li>
<li>开发一个大型网站你会考虑哪些问题?</li>
</ol>
<p>##美团面试题</p>
<ul>
<li>最近做的比较熟悉的项目是哪个，画一下项目技术架构图</li>
<li>JVM老年代和新生代的比例？</li>
<li>YGC和FGC发生的具体场景？</li>
<li>jstack，jmap，jutil分别的意义？如何线上排查JVM的相关问题？<ul>
<li>jps，java process status，进程状态</li>
<li>jstack，java stack，堆栈信息</li>
<li>jmap，java memory map，堆内存使用状态，常和jhat java heap analysis toolkit一起使用</li>
<li>jstat jvm统计监测</li>
<li>hprof Heap/CPU Profiling Tool，CPU使用率和堆使用状态</li>
</ul>
</li>
<li>线程池的构造类的方法的几个参数的具体意义？</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div></pre></td><td class="code"><pre><div class="line">ThreadPoolExecutor executor = new ThreadPoolExecutor(</div><div class="line">	corePoolSize,// 核心线程数  </div><div class="line">	maximumPoolSize, // 最大线程数  </div><div class="line">	keepAliveTime, // 闲置线程存活时间  </div><div class="line">	TimeUnit.MILLISECONDS,// 时间单位  </div><div class="line">	new LinkedBlockingDeque&lt;Runnable&gt;(),// 线程队列  </div><div class="line">	Executors.defaultThreadFactory(),// 线程工厂  </div><div class="line">	new AbortPolicy()// 队列已满,而且当前线程数已经超过最大线程数时的异常处理策略  </div><div class="line">); </div><div class="line">// 比如设置如下</div><div class="line">new ThreadPoolExecutor(</div><div class="line">10, 100, 60, TimeUnit.SECONDS, //限制最大线程，如果是CPU密集型的任务，核心线程就用核数，最大线程就用核数的N倍</div><div class="line">new ArrayBlockingQueue&lt;Runnable&gt;(1000),  //固定大小，防止内存堆积过多</div><div class="line">new NamedThreadFactory(&quot;third_retrieval&quot;),  //自己的ThreadFactory</div><div class="line">new ThreadPoolExecutor.DiscardPolicy())        //当任务对接的时候直接丢弃</div></pre></td></tr></table></figure>
<ul>
<li>单机上一个线程池正在处理服务如果忽然断电怎么办（正在处理和阻塞队列里的请求怎么处理）？</li>
<li>使用无界阻塞队列会出现什么问题？</li>
<li>接口如何处理重复请求？</li>
<li>具体的处理方案的是什么？</li>
<li>如何保证共享变量修改时的原子性？</li>
</ul>
<h2 id="滴滴面试题"><a href="#滴滴面试题" class="headerlink" title="滴滴面试题"></a>滴滴面试题</h2><ul>
<li>自我介绍</li>
<li>技术特点</li>
<li>兴趣是什么，优势是什么</li>
<li>Dubbo的底层原理，Zookeeper是什么</li>
<li>concurrentMap的机制；TreeMap；Volatil关键字</li>
<li>快速排序；广度优先搜索（队列实现）</li>
</ul>
<h2 id="京东面试题"><a href="#京东面试题" class="headerlink" title="京东面试题"></a>京东面试题</h2><ul>
<li>Dubbo超时重试；Dubbo超时时间设置</li>
<li>如何保障请求执行顺序</li>
<li>分布式事务与分布式锁（扣款不要出现负数）</li>
<li>分布式session设置</li>
<li>Zookeeper有那些作用</li>
<li>数据库垂直和水平拆分</li>
<li>MyBatis如何分页；如何设置缓存；MySQL分页</li>
<li>熟悉IO么？与NIO的区别，阻塞与非阻塞的区别</li>
<li>分布式session一致性</li>
<li>分布式接口的幂等性设计（不能重复扣款）</li>
</ul>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Java开发/" rel="tag">#Java开发</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/01/Algorithm/面试智力题/" rel="next" title="面试智力题">
                <i class="fa fa-chevron-left"></i> 面试智力题
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/01/Language/Java-concurrency/Java 多线程/" rel="prev" title="Java 多线程">
                Java 多线程 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    


  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/statics/images/avatar.png"
               alt="gatewayzy" />
          <p class="site-author-name" itemprop="name">gatewayzy</p>
          <p class="site-description motion-element" itemprop="description">blog website with hexo and github pages</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">70</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="https://github.com/gatewayzy" title="Github-gatewayzy" target="_blank">Github-gatewayzy</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://google.com/" title="Goolge" target="_blank">Goolge</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://wiki.jikexueyuan.com/" title="Wiki-jike" target="_blank">Wiki-jike</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#常规面试题"><span class="nav-number">1.</span> <span class="nav-text">常规面试题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#经典面试题"><span class="nav-number">2.</span> <span class="nav-text">经典面试题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#滴滴面试题"><span class="nav-number">3.</span> <span class="nav-text">滴滴面试题</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#京东面试题"><span class="nav-number">4.</span> <span class="nav-text">京东面试题</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">gatewayzy</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  
  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
  </script>

  <script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for (i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
    });
  </script>
  <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>



  

  
<script type="text/javascript" async src="//push.zhanzhang.baidu.com/push.js">
</script>


</body>
</html>
